//
//  HomeworkTableViewCell.m
//  parent
//
//  Created by IreWesT on 15/5/27.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "HomeworkTableViewCell.h"
#import "UIViewExt.h"
#import "UIImageView+WebCache.h"

@implementation HomeworkTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _initView];
    }
    return self;
}

//初始化子视图
- (void)_initView {

    _headView = [[UIImageView alloc] initWithFrame:CGRectMake(7.5, 14, 64, 64)];
    _headView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_headView];

    CGFloat tipWidth = 90.0f;
    _contentWidth = APP_SCREEN_WIDTH - _headView.right - tipWidth - 10;
    _title = [[UILabel alloc] initWithFrame:CGRectMake(_headView.right + 7.5, 20, _contentWidth, 14)];
    _title.backgroundColor = [UIColor clearColor];
    _title.textColor = UIColorMake(0, 91, 143);
    _title.font = [UIFont systemFontOfSize:14.0f];
    [self.contentView addSubview:_title];
    
    _content = [[UILabel alloc] initWithFrame:CGRectMake(_title.left, _title.bottom + 9, _contentWidth, 14)];
    _content.backgroundColor = [UIColor clearColor];
    _content.textColor = UIColorMake(55, 55, 55);
    _content.font = [UIFont systemFontOfSize:14.0f];
    _content.numberOfLines = 1;
    _content.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.contentView addSubview:_content];
    
    _tip = [[UILabel alloc] initWithFrame:CGRectMake(APP_SCREEN_WIDTH - 90, 20.5, 80, 11)];
    _tip.backgroundColor = [UIColor clearColor];
    _tip.textAlignment = NSTextAlignmentRight;
    _tip.textColor = UIColorMake(195, 195, 195);
    _tip.font = [UIFont systemFontOfSize:11.0f];
    [self.contentView addSubview:_tip];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    NSString *picUrl = [NSString stringWithFormat:@"%@/logo/%@/%@/%@_m.png", _picPrefix, _data[@"fc_id"], _data[@"sc_id"], _data[@"pid"]];
    [_headView sd_setImageWithURL:[NSURL URLWithString:picUrl]];
    _title.text = [NSString stringWithFormat:@"%@", _data[@"title"]];
    _content.text = [NSString stringWithFormat:@"%@", _data[@"descp"]];
    _tip.text = [NSString stringWithFormat:@"%@", _data[@"bname"]];

    CGSize size = [_content.text boundingRectWithSize:CGSizeMake(_content.width, 0)
                                              options:NSStringDrawingUsesLineFragmentOrigin
                                           attributes:@{NSFontAttributeName:_content.font}
                                              context:nil].size;

    _content.numberOfLines = 1;
    _content.height = 14.0f;
    if (size.height > 30) {
        _content.numberOfLines = 2;
        _content.height = 35.0f;
    }
}

@end
